package com.qianbao.qianbaobusiness.ui.cashier.databill;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.baseandroid.utils.FormatUtil;
import com.qianbao.qianbaobusiness.R;

import java.util.List;

/**
 * 分类汇总
 * 开发者：LuoYi
 * Time: 2017 10:37 2017/4/25 04
 */

public class DataBillAdapter extends BaseRecyclerViewAdapter<DayBillClassificationBean, BaseViewHolder> {

    public DataBillAdapter(Context context, List<DayBillClassificationBean> dayBillClassificationBeen) {
        super(context, dayBillClassificationBeen);
    }

    public void setRefreshAdapter(List<DayBillClassificationBean> dayBillClassificationBeen) {
        this.mDatas = dayBillClassificationBeen;
        notifyDataSetChanged();
    }

    @Override
    protected void bindView(BaseViewHolder holder, int position, DayBillClassificationBean model) {
        DataBillHolder dataBillHolder = (DataBillHolder) holder;
        dataBillHolder.amountTypeTv.setText(getAccountType(model.getChkAccountType()));
        dataBillHolder.amountNumberTv.setText(model.getAccountNum() == 0 ? "" : model.getAccountNum() + "笔");
        String settlementAmt = Double.parseDouble(model.getSettlementAmtTotal() + "") / 100 + "";
        dataBillHolder.amountExpenditureTv.setText("¥" + FormatUtil.getMoneyFormat(settlementAmt));
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.activity_data_bill_item, parent, false);
        return new DataBillHolder(mContext, view, this, getClickListener(), getLongClickListener());
    }

    class DataBillHolder extends BaseViewHolder {

        public TextView amountTypeTv;
        public TextView amountNumberTv;
        public TextView amountExpenditureTv;

        public DataBillHolder(Context context, View rootView, RecyclerView.Adapter adapter, OnRecyclerViewItemClickListener clickListener, OnRecyclerViewItemLongClickListener longClickListener) {
            super(context, rootView, adapter, clickListener, longClickListener);
            amountTypeTv = (TextView) rootView.findViewById(R.id.bill_amount_type_tv);
            amountNumberTv = (TextView) rootView.findViewById(R.id.bill_amount_number_tv);
            amountExpenditureTv = (TextView) rootView.findViewById(R.id.bill_amount_expenditure_tv);
        }
    }

    private String getAccountType(int accountType) {
        // 0:汇总 1：刷卡支付 2：支付宝 3：微信 4：钱包生活
        switch (accountType) {
            case 1:
                return "刷卡支付";
            case 2:
                return "支付宝支付";
            case 3:
                return "微信支付";
            case 4:
                return "钱包生活买单";
            default:
                return "全部";
        }
    }
}
